﻿
var _PageSize;
var _PageCount;
var _CurrentPage = 1;
var _ToPageBegin = true;

function Ajax_GetPageHtmlText(EventObj, ToPageBegin) {
    var obj = $("#ajaxPageInfo");

    if (_PageCount <= 0) {
        obj.hide();
        return;
    }
    obj.show();
    var HtmlText = "";
    if (_CurrentPage > 1) {
        if (ToPageBegin) {
            HtmlText = "<a href=\"#PageBegin\" class=\"PageCh\" onclick=\"" + EventObj + "('Up',1);\">上一页</a><a href=\"#PageBegin\" class=\"PageCh\" onclick=\"" + EventObj + "('Page',1);\">首页</a>";
        }
        else {
            HtmlText = "<a href=\"javascript:" + EventObj + "('page',1);\" class=\"PageCh\">上一页</a><a href=\"javascript:" + EventObj + "('page',1);\" class=\"PageCh\">首页</a>";
        }
    }
    else {
        HtmlText = "<a class=\"PageDisabled\" disabled=\"disabled\">上一页</a><a class=\"PageDisabled\" disabled=\"disabled\">首页</a>";
    }

    var PageNumI = 1;
    if (_PageCount > 10) {
        if (_CurrentPage > 3) {
            if (_PageCount - _CurrentPage < 8) {
                PageNumI = _PageCount - 9;
            } else {
                PageNumI = _CurrentPage - 2;
            }
        }
    }

    for (var i = PageNumI; i < PageNumI + 10 && i <= _PageCount; i++) {
        if (i == _CurrentPage) {
            HtmlText = "<a class=\"PageNow PageEn\">" + i + "</a>" + HtmlText;
        }
        else {
            if (ToPageBegin) {
                HtmlText = "<a href=\"#PageBegin\" onclick=\"" + EventObj + "('Page'," + i + ");\" class=\"PageEn\">" + i + "</a>" + HtmlText;
            }
            else {
                HtmlText = "<a href=\"javascript:" + EventObj + "('Page'," + i + ");\" class=\"PageEn\">" + i + "</a>" + HtmlText;
            }
        }
    }
    if (_CurrentPage < _PageCount) {
        if (ToPageBegin) {
            HtmlText = "<a href=\"#PageBegin\" class=\"PageCh\" onclick=\"" + EventObj + "('Down',1);\">下一页</a>" + HtmlText;
        }
        else {
            HtmlText = "<a href=\"javascript:" + EventObj + "('Down',1);\" class=\"PageCh\">下一页</a>" + HtmlText;
        }
    } else {
        HtmlText = "<a class=\"PageDisabled\" disabled=\"disabled\">下一页</a>" + HtmlText;
    }

    obj.html(HtmlText);
}
function PageData_Complete(result) {
    try {
        $("#ajaxDataList").show();
    }
    catch (ex) {
    }
    try {
        $("#ajaxPageInfo").show();
    }
    catch (ex) {
    }
    try {
        $("#trList_Loading").hide();
    }
    catch (ex) {
    }
    switch (result) {
        case "-1":
            location.reload();
            break;
        case "-2":

            $("#trList_Error").show();
            try {
                $("#ajaxPageInfo").hide();
            }
            catch (ex) {
            }
            $("#tdList_Error_Text").html("传入参数错误...");
            break;
        case "0":
            try {
                $("#ajaxPageInfo").hide();
            }
            catch (ex) {
            }
            try {
                $("#ajaxDataList").hide();
            }
            catch (ex) {
            }
            $("#trList_Error").show();
            $("#tdList_Error_Text").html("没有找到任何数据...");
            break;
        default:
            try {
                $("#trList_Button").hide();
            }
            catch (ex) {
            }
            $("#ajaxDataList").html(result);
            break;
    }
}
function PageData_Error() {
    $("#tdList_Error_Text").html("读取数据出错...");
    $("#trList_Error").show();
    try {
        $("#ajaxPageInfo").hide();
    }
    catch (ex) {
    }
    try {
        $("#ajaxDataList").show();
    }
    catch (ex) {
    }
    try {
        $("#trList_Loading").hide();
    }
    catch (ex) {
    }
    try {
        $("#trList_Button").hide();
    }
    catch (ex) {
    }
}

// 分页数据显示
function PageInfo_Complete(result) {
    try {
        _PageCount = result;
    } catch (ex) {
    }
    Ajax_GetPageHtmlText("Ajax_List_ToPage", _ToPageBegin);
}


//搜索分页翻页
function Ajax_List_ToPage(PageType, PageNo) {
    if (PageType == "Up") {
        if (_CurrentPage > 1) {
            _CurrentPage = _CurrentPage - 1;
        }
        else {
            alert('现在已经是第一页了');
            return;
        }
    } else if (PageType == "Down") {
        if (_CurrentPage < _PageCount) {
            _CurrentPage = _CurrentPage + 1;
        }
        else {
            alert('现在已经是最后一页了');
            return;
        }
    } else {
        _CurrentPage = PageNo;
    }
    Ajax_GetPageHtmlText("Ajax_List_ToPage", _ToPageBegin);
    Ajax_GetList(false);
}